package com.supply.dl.widget.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import butterknife.BindView;
import com.squareup.picasso.Picasso;
import com.supply.dl.R;
import com.supply.dl.bean.EnclosureBean;

import java.util.ArrayList;

public class ImageAdapter extends BaseAdapter
{
	private Context mContext;
	public ArrayList<EnclosureBean> jobAttachList = new ArrayList<EnclosureBean>(); //附件

	public ImageAdapter(Context context, ArrayList<EnclosureBean> goodList)
	{
		super();
		this.mContext = context;
		this.jobAttachList = goodList;
	}

//	@Override public ImageAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
//	{
//		return new ImageAdapter.MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_attach_layout, parent, false));
//	}
//
//	@Override public void onBindViewHolder(ImageAdapter.MyViewHolder holder, int position)
//	{
//		Picasso.with(mContext).load(jobAttachList.get(position).attachUrl).into(holder.imgAttach);
//	}

//	@Override public int getItemCount()
//	{
//		return jobAttachList.size();
//	}

	@Override public int getCount()
	{
		return jobAttachList.size();
	}

	@Override public Object getItem(int position)
	{
		return jobAttachList.get(position);
	}

	@Override public long getItemId(int position)
	{
		return position;
	}

	@Override public View getView(int position, View convertView, ViewGroup parent)
	{
		MyViewHolder viewHolder = null;
		if (convertView == null)
		{
			viewHolder = new MyViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_attach_layout, null);
			viewHolder.imgAttach = convertView.findViewById(R.id.img_attach);
			convertView.setTag(viewHolder);
		}
		else
		{
			viewHolder = (MyViewHolder) convertView.getTag();
		}
		Picasso.with(mContext).load(jobAttachList.get(position).attachUrl).into(viewHolder.imgAttach);
		return convertView;
	}

	class MyViewHolder
	{
		@BindView(R.id.img_attach) public ImageView imgAttach;
	}
}
